<template>
  <div class="component-teamCalc">
    <div class="component-mainHeader">
      <div class="top">
        <div class="topleft">
          <p>
            <span class="iconfont" style="color:#1abc9a;margin-right:3px;">&#xe607;</span>仓库管理
          </p>
        </div>
        <div class="topright">
          <el-button type="info" @click="$router.go(0)">
            <span style="font-weight:700;margin-right:5px;" class="iconfont">&#xe662;</span>刷新
          </el-button>
        </div>
      </div>
    </div>
    <div class="main">
      <div class="component-main-left">
        <div class="box1">
          <span class="iconfont">&#xe67e;</span>
          <span>{{editTitle}}</span>
          <div class="arrow"></div>
        </div>
      </div>
      <div class="component-main-right">
        <div class="box senInfo">
          <el-form
            :model="ruleForm"
            :rules="rules"
            ref="ruleForm"
            label-width="100px"
            class="demo-ruleForm"
          >
            <el-form-item label="仓库名称:" prop="storeName">
              <el-input v-model="ruleForm.storeName"></el-input>
            </el-form-item>
            <!--<el-form-item label="仓库位置:" prop="region">-->
            <!--<el-cascader-->
            <!--:options="options"-->
            <!--v-model="ruleForm.region"-->
            <!--style="width:326px;margin-left:1px;"-->
            <!--class="wd400">-->
            <!--</el-cascader>-->
            <!--</el-form-item>-->
            <el-form-item label="仓库位置:" prop="storeAddr">
              <el-input v-model="ruleForm.storeAddr"></el-input>
            </el-form-item>
            <el-form-item label="管理员姓名:">
              <el-input v-model="ms_username" disabled="disabled"></el-input>
              <!--<el-select v-model="ruleForm.managerName" clearable placeholder="管理员姓名" style="width: 360px;" @change="selectId">
                <el-option v-for="(item,index) in manageList" :key="index" :label="item.managerName" :value="item.managerId"></el-option>
              </el-select>-->
            </el-form-item>
            <el-form-item label="联系方式:" prop="tel">
              <el-input v-model="ruleForm.tel"></el-input>
            </el-form-item>
            <el-form-item label="仓库类型" prop="storeStatus">
              <el-select v-model="ruleForm.storeStatus" style="width:360px;" placeholder="请选择">
                <el-option label="实际" value="1"></el-option>
                <el-option label="虚拟" value="0"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="submitForm('ruleForm')">保存</el-button>
            </el-form-item>
          </el-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
  import area from '@/assets/js/area.js'
  export default {
    name:"teamCalc",
    data(){
      return {
        ms_username:localStorage.getItem("ms_username"),
        editTitle:'添加仓库',
        options:area, //省市区
        ruleForm: {
          storeName:'',
          storeAddr:'',
          region:[],
//          managerName:'',
          tel:'',
          storeStatus:''
        },
        rules: {
          storeName: [
            { required: true, message: "请输入仓库名称", trigger: "blur" },
          ],
          storeAddr: [
            { required: true, message: "请输入详细位置", trigger: "blur" },
          ],
          region:[
            { type: 'array',required: true, message: "请输入仓库位置", trigger: "change" },
          ],
         /* managerName: [
            { required: true, message: "请输入管理员姓名", trigger: "blur" },
          ],*/
          tel: [
            { required: true, message: "请输入联系方式", trigger: "blur" },
          ],
          storeStatus: [
            { required: true, message: '请选择仓库类型', trigger: 'change' }
          ],
        },
        workarea: ["", "", ""], //省市区
        manageList:[],
        newArray:{}
      };
    },
    mounted(){
//      this.manageLists();//管理员列表
      if(this.$route.params.flag == 0){
        this.editTitle = "添加仓库"
      }else{
        console.log(this.$route.params.info);
        this.ruleForm = this.deepClone(this.$route.params.info);
        this.editTitle = "编辑仓库"
      }
    },
    methods:{
      // 编辑 添加
      dataInit(){
        let that = this;
        let suCb = function(res){
          that.$message({
            message: '添加成功',
            type: 'success'
          });
          that.$router.push({name:'exWarehouse'})
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
          sysStore:{
            storeName: that.ruleForm.storeName,
            storeStatus: that.ruleForm.storeStatus,
            storeAddr: that.ruleForm.storeAddr,
            managerId: localStorage.getItem("ms_userId"),
            managerName: localStorage.getItem("ms_username"),
            tel: that.ruleForm.tel,
            storeId: that.$route.params.info.storeId || ''
          }
        }
        let palyParam = {
          url: "/api/web/sysStore/editSysStore",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      },
      //处理管理员的的名字跟id
      selectId(){
        this.newArray = this.manageList.find((item) => {
          if(item.managerId === this.ruleForm.managerName){
            return item
          }
        });
        console.log(this.newArray)
      },
      //省市区
      getArea(value, selectedData) {
        const areaName = selectedData.map(item => item.label)
        this.args = [...areaName]
        console.log(this.value2)
      },
      //表单提交
      submitForm(formName){
        console.log(this.ruleForm);
        this.$refs[formName].validate(valid => {
          if (valid) {
            this.dataInit();
          } else {
            console.log("error submit!!");
            return false;
          }
        });
      },
      //查询管理员
      manageLists(){
        let that = this;
        let suCb = function(res){
          that.manageList = res.data.data;
          that.newArray = that.manageList.find((item) => {
            if(item.managerId === that.$route.params.info.managerId){
              return item
            }
          });
          console.log(that.newArray)
          console.log(res.data)
        }
        let erCb = function(res){
          console.log(res)
        }
        let postData = {
        }
        let palyParam = {
          url: "/api/web/sysStore/selectManagerName",
          methods:'post',
          data: postData,
          success: suCb,
          error: erCb,
        }
        that.$https(palyParam)
      }
    }
  }
</script>

<style scoped>
  .main{
    overflow: hidden;
    width: 1100px;
    margin: 1px auto;
    border: 1px solid #e4e4e4;
    border-left:none;
    border-top: none;
  }
  .component-main-left {
    width: 180px;
    border: 1px solid #e4e4e4;
    padding-top: 50px;
    float: left;
    height: 600px;
    border-top: none;
    border-bottom: none;
  }
  .box1 {
    position: relative;
    width: 175px;
    height: 50px;
    text-align: left;
    line-height: 50px;
    background-color: #9ea7b4;
    color: #fff;
    padding-left: 5px;
  }
  .box1 .arrow {
    position: absolute;
    width: 0;
    height: 0;
    top: -40px;
    left: 180px;
    border-width: 25px 0 25px 25px;
    border-style: solid;
    border-color: transparent transparent transparent #9ea7b4; /*透明 透明 透明 灰*/
    margin: 40px auto;
  }
  .component-main-right{
    float: left;
  }
  .box{
    margin-left: 120px;
    margin-top: 80px;
    outline: none;
  }
  .el-button--primary{
    background-color: #1ABC9C;
    border-color: #1ABC9C;
  }

</style>
